const fs = require('fs'),
    path = require('path')

//递归调用
const loopDelete = dirPath => {
    const files = fs.readdirSync(dirPath)
    for (let i = 0; i < files.length; i++) {
        let item = files[i]
        const everyFilePath = path.join(dirPath, `${item}`)

        if (fs.statSync(everyFilePath).isFile()) {
            fs.unlinkSync(everyFilePath)
        } else {
            loopDelete(everyFilePath)
            fs.rmdirSync(everyFilePath)
        }
    }
}


//查看当前目录下的文件或者文件夹
const listFilesAndDirs = path => {
    const files = fs.readdirSync(path)
    let arr = []
    for (let i = 0; i < files.length; i++) {
        let filePath = path + '/' + files[i]
        if (fs.statSync(filePath).isDirectory()) {
            arr.push(files[i] + '/')
        } else {
            arr.push(files[i])
        }
    }
    return arr
}
module.exports = {
    loopDelete,
    listFilesAndDirs
}